namespace EyeSoft.Wpf.Facilities
{
	using System;
	using System.Collections.Generic;
	using System.Linq;
	using System.Linq.Expressions;
	using System.Reflection;

	using EyeSoft.Reflection;

	public class DependentProperty
	{
		private readonly List<string> propertiesDependencies =
			new List<string>();

		internal DependentProperty(PropertyInfo dependentPropertyInfo)
		{
			PropertyName = dependentPropertyInfo.Name;
		}

		internal string PropertyName { get; private set; }

		public DependentProperty DependsOn(params Expression<Func<object>>[] propertyExpression)
		{
			propertiesDependencies
				.AddRange(propertyExpression.Select(property => property.PropertyName()));

			return this;
		}

		internal bool HasToRefresh(string propertyName)
		{
			return propertiesDependencies.Contains(propertyName);
		}
	}
}